'''※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
File Name: getconfig.py
Author: GID5564
Description: 读取配置文件
Version: 1.0
Created Time: 04/09/23-09:55:45
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※'''
  
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os
from common.Path import CONFDIR
 
 
class Config(ConfigParser):
 
    def __init__(self,f_name):
        """
        初始化
        将配置文件读取出来
        super().    调用父类
        """
        self.conf_name = os.path.join(CONFDIR, f_name)
        super().__init__()
        super().read(self.conf_name, encoding='utf-8')
 
    def getAllsections(self):
        """
        :return: 返回所有的节点名称
        """
        return super().sections()
 
    def getOptions(self, sectioName):
        """
        :param sectioName: 节点名称
        :return: 返回节点所有的key
        """
        return super().options(sectioName)
 
    def getItems(self, sectioName):
        """
        :param sectioName: 节点名称
        :return: 返回节点的所有item
        """
        return super().items(sectioName)
 
    def getValue(self, sectioName, key):
        """
        :param sectioName: 节点的名称
        :param key: key名称
        :return: 返回sectioName下key 的value
        """
        return super().get(sectioName, key)
 
    def saveData(self, sectioName, key, value):
        """
        添加配置
        :param sectioName: 节点名称
        :param key: key名
        :param value: 值
        :return:
        """
        super().set(section=sectioName, option=key, value=value)
        super().write(fp=open(self.conf_name, 'w'))
 
 
